package main.java.bean;

import java.lang.reflect.Field;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;

import main.java.constant.Constant;

public class Form {
	
	public static Logger logger = Logger.getLogger("Form");
	
	public Form() {}
	
	public static ActionForm full(String path,HttpServletRequest request){
		
		ActionForm form = null;
		try {
			Class<ActionForm> clazz = (Class<ActionForm>) Class.forName(path);
			form = clazz.newInstance();
			Field[] fields = clazz.getDeclaredFields();
			for(Field field:fields){
				field.setAccessible(true);
				field.set(form, request.getParameter(field.getName()));
				field.setAccessible(false);
			}
		} catch (ClassNotFoundException e) {
			logger.info(Constant.EXCEPTIONMSG+e);
		} catch (InstantiationException e) {
			logger.info(Constant.EXCEPTIONMSG+e);
		} catch (IllegalAccessException e) {
			logger.info(Constant.EXCEPTIONMSG+e);
		}
		return form;
	} 
	
}
